package com.zret.oasys.operation.emp;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.zret.oasys.dbtools.MD5Util;
import com.zret.oasys.entity.Emp;

public class AddEmp implements EmpServletOperation {

	@Override
	public void doOperation(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 添加员工Servletop判断AddEmp
		//设置json编码
		response.setContentType("application/json;charset=utf-8");
		String position =request.getParameter("position");
		int deptid =Integer.valueOf(request.getParameter("deptid"));
		String empname =request.getParameter("empname");
		String sex =request.getParameter("sex");
		String hiredate =request.getParameter("hiredate");
		double salary =Double.valueOf(request.getParameter("salary"));
		String username =request.getParameter("username");
		//密码MD5加密
		String password=MD5Util.getEncodeByMd5(request.getParameter("password"));
		int faceflag=Integer.valueOf(request.getParameter("faceflag"));
		Emp emp = new Emp(position, deptid, empname, sex, hiredate, salary, username, password, faceflag);
		boolean flag = empService.addEmps(emp);
		System.out.println(flag);
		//网页ajax输出
		PrintWriter out = response.getWriter();
		//String msg ="{'msg':'添加员工成功'}";
		Gson gson =new Gson();
		String msg1 = gson.toJson("添加员工成功");
		String msg2 = gson.toJson("添加员工失败,检查用户名是否重复");
		if (flag) {
			out.print(msg1);
		}else {
			out.print(msg2);
		}
		out.close();
	}

}
